#include <iostream>

using namespace std;
#include"concrete_observer.h"
#include"concrete_subject.h"
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if(p) {delete(p); (p) = nullptr;} }
#endif
int main()
{
    ISubject *subject=new SubjectA();
    IObserver *observer1=new ObserverA("Jack");
    IObserver *observer2=new ObserverA("Pony");

    subject->Attach(observer1);
    subject->Attach(observer2);
     subject->Notify();
    static_cast<SubjectA*>(subject)->SetPrice(12.5);
    subject->Notify();

    subject->Detach(observer1);
    static_cast<SubjectA*>(subject)->SetPrice(15.0);
    subject->Notify();


  cout<<   static_cast<SubjectA*>(subject)->GetPrice()<<endl;
    SAFE_DELETE(observer1);
    SAFE_DELETE(observer2);
    SAFE_DELETE(subject);
    getchar();

    return 0;
}
